import $http from '@/api/request.js'
import store from '@/store/index.js'
import pop from '@/common/pop.js'

class Api {

	async myMoney() {
		try {
			const response = await $http.get({
				url: '/DiyApi/myMoney'
			})
			if (response.code != 200) {
				pop.Toast(response.msg)
				throw new Error(response.msg)
			}
			return response.data
		} catch (error) {
			throw error
		}
	}


	async recharge(money, aesId, aesVerifyCode) {
		const requestData = {
			VeriCode: store.state.bid,
			vId: store.state.vid,
			payType: 1,
			money,
			aesId,
			aesVerifyCode
		}
		try {
			const response = await $http.post({
				url: '/SRA_memberRecharge/recharge',
				data: requestData
			})
			if (response.code != 100) {
				pop.Toast(response.msg)
				throw new Error(response.msg)
			}
			return response.data
		} catch (error) {
			throw error
		}
	}


	async getPreferential(Item) {
		let url;
		let params = {
			vId: store.state.vid,
			couponsId: Item.couponsId, // 优惠卷id
			useIntegral: Item.useIntegral, // 是否使用积分抵扣 1 、0
			express: Item.pageData.express
		}
		if (Item.goods_id) {
			url = '/SRA_simMallApi/getPreferential3'
			params['specs_bind_id'] = Item.specs.specs_bind_id ?? ''
			params['goods_id'] = Item.goods_id
			params['num'] = Item.goods_num
			params['single'] = Item.goods_id && Item.open_group != 1 ? 1 : 0
		} else {
			url = '/SRA_simMallApi/getPreferential2'
			params['carIds'] = Item.car_id
			params['operationId'] = ''
		}
		const response = await $http.get({
			url,
			data: params
		})
		if (response.code != 100) {
			pop.Toast(response.msg)
			throw new Error(response.msg)
		}
		return response.data
	}



	async BrandInfo(brand_id) {
		let url = '/singleSaleApi/getGoodsBrandInfo'
		let params = {
			brand_id
		}
		const response = await $http.post({
			url,
			data: params
		})
		if (response.code !== '100') {
			pop.Toast(response.msg)
			throw new Error(response.msg)
		}
		return response.data
	}

	async getConfig() {
		let url = '/gsyxcxApi/getConfig'
		const response = await $http.post({
			url
		})
		if (response.errcode != '100') {
			pop.Toast(response.msg)
			throw new Error(response.msg)
		}
		return response.data
	}

	// 获取支付参数
	async getRechargeAct(params) {
		let url = '/SRA_memberRecharge/getRechargeAct'
		const response = await $http.get({
			url,
			data: params
		})
		if (response.code != '100') return pop.Toast(response.msg)

		return response.data
	}

	// 获取支付信息
	async recharge(data) {
		let url = '/SRA_memberRecharge/recharge'
		const response = await $http.get({
			url,
			data
		})
		if (response.code != '100') return pop.Toast(response.msg)

		return response.data
	}
	
	// 获取订单数量
	async getListCount(data) {
		let url = '/orderRepairApi/getListCount'
		const response = await $http.get({
			url,
			data
		})
		if (response.code != '200') return pop.Toast(response.msg)
	
		return response.data
	}
	
	// 商品详情
	async singleDetails(goods_id){
		let url = '/singleSaleApi/singleDetails'
		const response = await $http.get({
			url,
			data:{
				goods_id
			}
		})
		if (response.errcode != '100') return pop.Toast(response.msg)
			
		return response.data
	}
	
   // 收藏商品
   async goodsCollect(goods_id){
	   let url = '/singleSaleApi/goods_collect'
	   const response = await $http.post({
	   	url,
	   	data:{
	   		goods_id
	   	}
	   })
	   if (response.code != '200') return pop.Toast(response.msg)
	   	
	   return '1'
   }
   
   // 订单详情
   async repairOrderDetail(data){
   	   console.log(data,'data');
   	   let url = '/orderRepairApi/repairOrderDetail'
   	   const response = await $http.get({
   	   	url,
   	   	data
   	   })
   	   if (response.code != '200') return pop.Toast(response.msg)
   	   	
   	   return response.data
   }

   
   // 取消预约
   async cancelOrder(repair_id){
   	   let url = '/orderRepairApi/cancelOrder'
   	   const response = await $http.post({
   	   	url,
   	   	data:{
   	   		repair_id
   	   	}
   	   })
   	   if (response.code != '200') return pop.Toast(response.msg)
   	   	
   	   return response.data
   }
   
   // 师傅首页
  
  async masterInfo(repair_id){
  	   let url = '/orderRepairApi/masterInfo'
  	   const response = await $http.get({
  	   	url,
  	   })
  	   if (response.code != '200') return pop.Toast(response.msg)
  	   	
  	   return response.data
  }
  
  // 师傅拒单
  async refuseOrder(repair_id,reason){
  	   let url = '/orderRepairApi/refuseOrder'
  	   const response = await $http.post({
  	   	url,
		data:{
			repair_id,
			reason
		}
  	   })
  	   if (response.code != '200') return pop.Toast(response.msg)
  	   	
  	   return response.data
  }
  
  // 签到
  async postAcceptOrder(repair_id){
  	   let url = '/orderRepairApi/acceptOrder'
  	   const response = await $http.post({
  	   	url,
  		data:{
  			repair_id,
  		}
  	   })
  	   if (response.code != '200') return pop.Toast(response.msg)
  	   	
  	   return response.data
  }
  
  // 上传资料
  async postUploadSign(repair_id,sign_desc,sign_pic){
  	   let url = '/orderRepairApi/uploadSign'
  	   const response = await $http.post({
  	   	url,
  		data:{
  			repair_id,
  			sign_desc,
  			sign_pic:sign_pic.join(',')
  		}
  	   })
  	   if (response.code != '200') return pop.Toast(response.msg)
  	   	
  	   return response.data
  }
  
  
  // 复核价格
  async postModifyMoney(repair_id,payment){
  	   let url = '/orderRepairApi/modifyMoney'
  	   const response = await $http.post({
  	   	url,
  		data:{
  			repair_id,
  			payment,
  		}
  	   })
  	   if (response.code != '200') return pop.Toast(response.msg)
  	   	
  	   return response.data
  }
  // 开始服务
  async postStartOrder(repair_id){
  	   let url = '/orderRepairApi/startOrder'
  	   const response = await $http.post({
  	   	url,
  		data:{
  			repair_id,
  		}
  	   })
  	   if (response.code != '200') return pop.Toast(response.msg)
  	   	
  	   return response.data
  }
  
  // 完成服务
  async postCompleteOrder(repair_id,confirm_code,confirm_cer_pic,confirm_pic){
	  pop.showLoading('');
  	   let url = '/orderRepairApi/completeOrder'
  	   const response = await $http.post({
  	   	url,
  		data:{
  			repair_id,
			confirm_code,
			confirm_cer_pic:confirm_cer_pic.join(','),
			confirm_pic:confirm_pic.join(',')
  		}
  	   })
	   pop.hideLoading();
  	   if (response.code != '200') return pop.Toast(response.msg)
  	   	
  	   return response.data
  }
  
  
  // 扣分筛选项目
  async getMasterPointFilter(){
  	   let url = '/orderRepairApi/getMasterPointFilter'
  	   const response = await $http.get({
  	   	url,
  	   })
  	   if (response.code != '200') return pop.Toast(response.msg)
  	   	
  	   return response.data
  }
}
export default new Api()